﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace BinProtoCode
{
    class Program
    {

        static public void ProcessBinProto()
        {
            try
            {
                Console.WriteLine("{0} 开始检查文件列表...", Common.NowTime());
                MeFile.InitFileList();

                string[] allFileName = MeFile.GetNameList();// 文件名 无后缀

                Proto.Init();// 初始化proto文件头
                Encoder.StartCode();

                foreach (string fileName in allFileName)
                {
                    int nRes = Common.ParseExcel(fileName);
                    if (0 != nRes)
                    {
                        Console.WriteLine("{0} {1}...", Common.NowTime(), fileName);
                        Console.WriteLine("[{0}]分页 [{1}]列解析出错...", Common.nSheetIndex.ToString(), nRes.ToString());

                        Common.EndParse();
                        return;
                    }

                    Console.WriteLine("解析完成————[{0}]", fileName);
                }
                Encoder.EndCode();
                // 保存proto文件
                Proto.SaveProto();

                Console.WriteLine("全部解析完成");

                // 调用批处理生成cs代码(仅工具使用)
                Process xProcess = new Process();
                xProcess.StartInfo.FileName = System.Environment.CurrentDirectory + @".\cscode.bat";
                xProcess.StartInfo.UseShellExecute = true;
                xProcess.Start();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("{0}", ex.ToString());
            }
            finally
            {
                Common.EndParse();
            }
        }
        static void Main(string[] args)
        {
            ProcessBinProto();
            Console.WriteLine("请按任意键继续...");
            Console.ReadKey();
        }
    }
}
